home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 July / EnigmA AMIGA RUN 20 (1997)(G.R. Edizioni)(IT)[!][issue 1997-07 & 08][EAR-CD IV].iso / earcd / text / misc / nroff.lha / nroff / nroff.h < prev    next >
C/C++ Source or Header  |  1997-02-10  |  16KB  |  591 lines

  1. #ifndef NRO_H
  2. #define NRO_H
  3.  
  4. #include "config.h"            /* os/compiler options */
  5. #include "ctype.h"
  6. /*
  7.  *    nroff.h - stuff for nroff
  8.  *
  9.  *    adapted for atariST/TOS by Bill Rosenkranz 10/89
  10.  *    net:    rosenkra@hall.cray.com
  11.  *    CIS:    71460,17
  12.  *    GENIE:    W.ROSENKRANZ
  13.  *
  14.  *    things to look for here:
  15.  *    1) TMAC definition for default macro package lib
  16.  *    2) configuration sizes (see _STKSIZ below if alcyon/dri)
  17.  *    3) libc should have getenv(), time(), and ctime()
  18.  *    4) look in version.h for *printer file name (included below)
  19.  *
  20.  *    all data is currently allocated in static arrays. the biggest
  21.  *    chunks are the parameters which control number registers and the
  22.  *    macro name space area. these are defined below: MAXREGS, MACBUF.
  23.  *    MACBUF is the larger. it holds all macros, strings, etc. if you
  24.  *    find yourself running out of macro space, increase MACBUF.
  25.  *
  26.  *    original author:
  27.  *
  28.  *    Stephen L. Browning
  29.  *    5723 North Parker Avenue
  30.  *    Indianapolis, Indiana 46220
  31.  *
  32.  *    history:
  33.  *
  34.  *    - Originally written in BDS C;
  35.  *    - Adapted for standard C by W. N. Paul
  36.  *    - Heavily hacked up to conform to "real" nroff by Bill Rosenkranz
  37.  */
  38.  
  39. #include <ctype.h>
  40.  
  41. /*
  42.  *    default prefix of macro files. files will be of the form "tmac.an"
  43.  *    (for -man), "tmac.s" (for -ms), "tmac.e" (for -me), etc. first
  44.  *    checks environment for TMACDIR which would be path (e.g. "c:\lib\tmac"
  45.  *    or ".", no trailing slash char!).
  46.  */
  47. #ifdef tmacfull
  48. # define TMACFULL    tmacfull
  49. #endif
  50. #ifdef tmacpre
  51. # define TMACPRE    tmacpre
  52. #endif
  53.  
  54. #ifdef GEMDOS
  55. # ifndef TMACFULL
  56. #  define TMACFULL    "c:\\lib\\tmac\\tmac."
  57. # endif
  58. # ifndef TMACPRE
  59. #  define TMACPRE    "\\tmac."
  60. # endif
  61. #endif
  62.  
  63. #ifdef MINIX
  64. # ifndef TMACFULL
  65. #  define TMACFULL    "/usr/lib/tmac/tmac."
  66. # endif
  67. # ifndef TMACPRE
  68. #  define TMACPRE    "/tmac."
  69. # endif
  70. #endif
  71.  
  72. #ifdef UNIX
  73. # ifndef TMACFULL
  74. #  define TMACFULL    "/usr/lib/tmac/tmac."
  75. # endif
  76. # ifndef TMACPRE
  77. #  define TMACPRE    "/tmac."
  78. # endif
  79. #endif
  80.  
  81. #ifdef _AMIGA
  82. # ifndef TMACFULL
  83. #  define TMACFULL    "PROGDIR:tmac."
  84. # endif
  85. # ifndef TMACPRE
  86. #  define TMACPRE    "/tmac."
  87. # endif
  88. #endif
  89.  
  90. /*
  91.  *    command codes. indented defines are commands not yet implemented
  92.  */
  93. #undef PI
  94. #define MACRO        0    /* macro definition */
  95. #define BP         1    /* begin page */
  96. #define BR         2    /* break */
  97. #define CE         3    /* center */
  98. #define FI         4    /* fill    */
  99. #define FO         5    /* footer */
  100. #define HE         6    /* header */
  101. #define IN         7    /* indent */
  102. #define LS         8    /* line spacing    */
  103. #define NF         9    /* no fill */
  104. #define PL        10    /* page length */
  105. #define RM        11    /* remove macro */
  106. #define SP        12    /* line space */
  107. #define TI        13    /* temp indent */
  108. #define UL        14    /* underline */
  109. #define JU        15    /* justify */
  110. #define NJ        16    /* no justify */
  111. #define M1        17    /* top margin */
  112. #define M2        18    /* second top margin */
  113. #define M3        19    /* first bottom margin */
  114. #define M4        20    /* bottom-most margin */
  115. #define BS        21    /* allow/disallow '\b' in output */
  116. #define NE        22    /* need n lines */
  117. #define PC        23    /* page number character (%) */
  118. #define CC        24    /* control character (.) */
  119. #define PO        25    /* page offset */
  120. #define BO        26    /* bold face */
  121. #define EH        27    /* header for even numbered pages */
  122. #define OH        28    /* header for odd numbered pages */
  123. #define EF        29    /* footer for even numbered pages */
  124. #define OF        30    /* footer for odd numbered pages */
  125. #define SO        31    /* source file */
  126. #define CU        32    /* continuous underline    */
  127. #define DE        33    /* define macro    */
  128. #define EN        34    /* end macro definition    */
  129. #define NR        35    /* set number register */
  130. #define EC        36    /* escape character (\) */
  131. #define FT        37    /* font change (R,B,I,S,P) */
  132. #define EO        38    /* turn escape parsing off */
  133. #define LL        39    /* line length (same as RM) */
  134. #define FL        40    /* flush output NOW */
  135. #define PN        41    /* page number for next page */
  136. #define RR        42    /* remove register */
  137. #define C2        43    /* nobreak char */
  138. #  define TR        44    /* translate character */
  139. #define LT        45    /* length of title */
  140. #  define FC        46    /* field delimeter */
  141. #define TL        47    /* like HE */
  142. #define AF        48    /* assign format to nr */
  143. #define AD        49    /* adjust line */
  144. #define NA        50    /* no adjust */
  145. #define DS        51    /* define string */
  146. #define PM        52    /* print macro names */
  147. #define IF        53    /* if */
  148. #  define IE        54    /* if/else */
  149. #  define EL        55    /* else */
  150. #define PS        56    /* point size (IGNORED in nroff) */
  151. #define SS        57    /* space char size (IGNORED in nroff) */
  152. #define CS        58    /* constant char space (IGNORED in nroff) */
  153. #define BD        59    /* embolden font (IGNORED in nroff) */
  154. #  define FP        60    /* font position */
  155. #  define MK        61    /* mark vertical place */
  156. #  define RT        62    /* return to marked vert place */
  157. #  define VS        63    /* vertical baseline spacing */
  158. #  define SV        64    /* save vertical distance */
  159. #  define OS        65    /* output saved vertical distance */
  160. #  define NS        66    /* no-space mode */
  161. #  define RS        67    /* restore spacing mode */
  162. #  define AM        68    /* append to macro */
  163. #  define AS        69    /* append to string */
  164. #  define RN        70    /* rename */
  165. #  define DI        71    /* divert to macro */
  166. #  define DA        72    /* divert/append to macro */
  167. #  define WH        73    /* set location trap */
  168. #  define CH        74    /* change trap location */
  169. #  define DT        75    /* set diversion trap */
  170. #  define IT        76    /* set input line trap */
  171. #  define EM        77    /* end macro */
  172. #  define TA        78    /* tab settings */
  173. #  define TC        79    /* tab repetition char */
  174. #  define LC        80    /* leader repetition char */
  175. #  define LG        81    /* ligature mode */
  176. #  define UF        82    /* underline font */
  177. #  define NH        83    /* no hyphenation */
  178. #  define HY        84    /* hyphenate */
  179. #  define HC        85    /* hyphenation indication char */
  180. #  define HW        86    /* hyphenation exception words */
  181. #  define NM        87    /* number mode */
  182. #  define NN        88    /* no number next lines */
  183. #  define EV        89    /* environment switch */
  184. #  define RD        90    /* read insertion */
  185. #  define EX        91    /* exit */
  186. #  define NX        92    /* next file */
  187. #  define PI        93    /* pipe to program */
  188. #  define MC        94    /* set margin char */
  189. #  define TM        95    /* print to terminal */
  190. #define IG        96    /* ignore */
  191.  
  192. #define COMMENT        1000    /* comment (.\") */
  193. #define UNKNOWN        -1
  194.  
  195.  
  196. /*
  197.  *    MAXLINE is set to a value slightly larger than twice the longest
  198.  *    expected input line. Because of the way underlining is handled, the
  199.  *    input line which is to be underlined, can almost triple in length.
  200.  *    Unlike normal underlining and boldfacing, continuous underlining
  201.  *    affects all characters in the buffer, and represents the worst case
  202.  *    condition.  If the distance between the left margin and the right
  203.  *    margin is greater than about 65 characters, and continuous underlining
  204.  *    is in effect, there is a high probability of buffer overflow.
  205.  */
  206. #define MAXLINE        500        /* 200 */
  207. #define PAGELEN         66
  208. #define PAGEWIDTH     80
  209. #define HUGE        256
  210. #define INFINITE    32760
  211. #define LEFT        0    /* indecies into hdr margin lim arrays */
  212. #define RIGHT        1
  213. #define Nfiles        4    /* nesting depth for input files */
  214.  
  215. /*
  216.  *    The following parameters may be defined elsewhere so undef/def
  217.  */
  218. #undef min
  219. #undef max
  220. #undef YES
  221. #define YES        1
  222. #undef NO
  223. #define NO        0
  224. #undef ERR
  225. #define ERR        -1
  226. #define EOS         '\0'
  227. #undef FALSE
  228. #define FALSE         0
  229. #undef TRUE
  230. #define TRUE         !FALSE
  231. #undef OK
  232. #define OK         !ERR
  233.  
  234. /*
  235.  *    a rational way of dealing with the NULL thing...
  236.  */
  237. #define NULL_CPTR    (char *) 0
  238. #define NULL_FPTR    (FILE *) 0
  239. #define NULL_IPTR    (int *) 0
  240. #define NULL_LPTR    (long *) 0
  241. #define NULL_SPTR    (short *) 0
  242. #define NULL_PTR    (char *) 0
  243. #define NULLP(type)    (type *) 0
  244.  
  245.  
  246. /*
  247.  *    for justification during line fill
  248.  */
  249. #define ADJ_OFF        0
  250. #define ADJ_LEFT    1
  251. #define ADJ_RIGHT    2
  252. #define ADJ_CENTER    3
  253. #define ADJ_BOTH    4
  254.  
  255.  
  256. /*
  257.  *    basic unit (b.u.) conversions. in nroff, all output is fixed spaced,
  258.  *    at least in THIS nroff. so unit conversion to b.u. amount to 1 Em per
  259.  *    character or 24 b.u. per character. thus 0.5i = 120 b.u. = 5 chars.
  260.  *    everything is rounded up to the nearest Em. it is highly recommended
  261.  *    to use inches for everything...
  262.  *
  263.  *    to convert (say inches) to char spaces, do this:
  264.  *
  265.  *        char_spaces = (int)(inches * (float) BU_INCH) / BU_EM;
  266.  */
  267. #define BU_INCH        240        /* 1.0i = 240 b.u. */
  268. #define BU_CM        945/10        /* 1.0c = 240*50/127 b.u. */
  269. #define BU_PICA        40        /* 1P   = 240/6 b.u. */
  270. #define BU_EM        24        /* 1m   = 240/10 b.u. (10 char/inch) */
  271. #define BU_EN        24        /* 1n   = 240/10 b.u. */
  272. #define BU_POINT    240/72        /* 1p   = 240/72 b.u. */
  273. #define BU_BU        1        /* 1    = 1 b.u. */
  274.  
  275.  
  276. /*
  277.  *    The parameter values selected for macro definitions are somewhat
  278.  *    arbitrary.  MACBUF is the storage area for both macro names and
  279.  *    definitions.  Since macro processing is handled by pushing back
  280.  *    the expansion into the input buffer, the longest possible expansion
  281.  *    would be MAXLINE characters.  Allowing for argument expansion,
  282.  *    MXMLEN was chosen slightly less than MAXLINE. It is assumed that
  283.  *    most macro definitions will not exceed 20 characters, hence MXMDEF
  284.  *    of 150.
  285.  */
  286.  
  287. #define MXMDEF        150    /* max no. of macro definitions */
  288. #define MACBUF        100000    /* macro definition buffer size (32000) */
  289. #define MXMLEN        2000    /* max length of each macro definition (250) */
  290. #define MNLEN        10    /* max length of macro name */
  291. #define MAXREGS        100    /* max number of registers (2-char) */
  292. #define MAXPBB        5000    /* size of push back buffer */
  293.  
  294. struct macros
  295. {
  296.     char   *mnames[MXMDEF];    /* table of ptrs to macro names */
  297.     int    lastp;        /* index to last mname    */
  298.     char   *emb;        /* next char avail in macro defn buf */
  299.     char     mb[MACBUF];    /* table of macro definitions */
  300.     char   *ppb;        /* pointer into push back buffer */
  301.     char     pbb[MAXPBB];    /* push back buffer */
  302. };
  303.  
  304.  
  305. /*
  306.  *    number registers
  307.  */
  308. #define RF_READ        0x0001    /* register flags */
  309. #define RF_WRITE    0x0002
  310.  
  311. struct regs
  312. {
  313.     char    rname[4];    /* 2-char register name */
  314.     int    rauto;        /* autoincrement value */
  315.     int    rval;        /* current value of the register */
  316.     int    rflag;        /* register flags */
  317.     char    rfmt;        /* register format (1,a,A,i,I,...) */
  318. };
  319.  
  320.  
  321.  
  322. /*
  323.  *    control parameters for nroff
  324.  */
  325. struct docctl
  326. {
  327.     int    fill;        /* fill if YES, init = YES */
  328.     int    dofnt;        /* handle font change, init = YES */
  329.     int    lsval;        /* current line spacing, init = 1 */
  330.     int    inval;        /* current indent, >= 0, init = 0 */
  331.     int    rmval;        /* current right margin, init = 60 */
  332.     int    llval;        /* current line length, init = 60 */
  333.     int    ltval;        /* current title length, init = 60 */
  334.     int    tival;        /* current temp indent, init = 0 */
  335.     int    ceval;        /* number of lines to center, init = 0 */
  336.     int    ulval;        /* number of lines to underline, init = 0 */
  337.     int    cuval;        /* no lines to continuously uline, init = 0 */
  338.     int    juval;        /* justify if YES, init = YES */
  339.     int    adjval;        /* adjust type, init = ADJ_BOTH */
  340.     int    boval;        /* number of lines to bold face, init = 0 */
  341.     int    bsflg;        /* can output contain '\b', init = FALSE */
  342.     int    prflg;        /* print on or off, init = TRUE */
  343.     int    sprdir;        /* direction for spread(), init = 0 */
  344.     int    flevel;        /* nesting depth for source cmd, init = 0 */
  345.     int    lastfnt;    /* previous used font */
  346.     int    thisfnt;    /* current font, init = 1 (1=R,2=I,3=B,4=S) */
  347.     int    escon;        /* whether esc parsing is on, init = YES */
  348.     int    nr[26];        /* number registers */
  349.     int    nrauto[26];    /* number registers auto increment */
  350.     char    nrfmt[26];    /* number registers formats, init = '1' */
  351.                 /* input code how printed */
  352.                 /* 1     '1'  1,2,3,... */
  353.                 /* a     'a'  a,b,c,...,aa,bb,cc,... */
  354.                 /* A     'A'  A,B,C,...,AA,BB,CC,... */
  355.                 /* i     'i'  i,ii,iii,iv,v... */
  356.                 /* I     'I'  I,II,III,IV,V... */
  357.                 /* 01     2   01,02,03,... */
  358.                 /* 001    3   001,002,003,... */
  359.                 /* 0..1   8   00000001,00000002,... */
  360.     char    pgchr;        /* page number character, init = '%' */
  361.     char    cmdchr;        /* command character, init = '.' */
  362.     char    escchr;        /* escape char, init = '\' */
  363.     char    nobrchr;    /* nobreak char, init = '\'' */
  364. };
  365.  
  366.  
  367. /*
  368.  *    output buffer control parameters
  369.  */
  370. struct cout
  371. {
  372.     int    outp;        /* next avail char pos in outbuf, init = 0 */
  373.     int    outw;        /* width of text currently in buffer */
  374.     int    outwds;        /* number of words in buffer, init = 0 */
  375.     int    lpr;        /* output to printer, init = FALSE */
  376.     int    outesc;        /* number of escape char on this line */
  377.     char    outbuf[MAXLINE];/* output of filled text */
  378. };
  379.  
  380.  
  381. /*
  382.  *    page control parameters
  383.  */
  384. struct page
  385. {
  386.     int    curpag;        /* current output page number, init =0 */
  387.     int    newpag;        /* next output page number, init = 1 */
  388.     int    lineno;        /* next line to be printed, init = 0 */
  389.     int    plval;        /* page length in lines, init = 66 */
  390.     int    m1val;        /* margin before and including header */
  391.     int    m2val;        /* margin after header */
  392.     int    m3val;        /* margin after last text line */
  393.     int    m4val;        /* bottom margin, including footer */
  394.     int    bottom;        /* last live line on page
  395.                     = plval - m3val - m4val    */
  396.     int    offset;        /* page offset from left, init = 0 */
  397.     int    frstpg;        /* first page to print, init = 0 */
  398.     int    lastpg;        /* last page to print, init = 30000 */
  399.     int    ehlim[2];    /* left/right margins for headers/footers */
  400.     int    ohlim[2];    /* init = 0 and PAGEWIDTH */
  401.     int    eflim[2];
  402.     int    oflim[2];
  403.     char    ehead[MAXLINE];    /* top of page title, init = '\n' */
  404.     char    ohead[MAXLINE];
  405.     char    efoot[MAXLINE];    /* bottom of page title, init = '\n' */
  406.     char    ofoot[MAXLINE];
  407. };
  408.  
  409.  
  410.  
  411. /*
  412.  *    forward refs from libc
  413.  */
  414. char   *getenv ();
  415. char   *ctime ();
  416. long    time ();
  417. #ifdef UNIX
  418. char   *tgetstr ();            /* from termcap/terminfo */
  419. #endif
  420. #ifdef MINIX_ST
  421. char   *tgetstr ();
  422. #endif
  423. #ifdef MINIX_PC
  424. char   *tgetstr ();
  425. #endif
  426.  
  427.  
  428. /*
  429.  *    forward refs from nroff
  430.  */
  431. char   *getmac ();
  432. char   *getstr ();
  433. char   *skipwd ();
  434. char   *skipbl ();
  435. char   *getfield ();
  436.  
  437. int    do_mc ();
  438. int    comand ();
  439. int    comtyp ();
  440. int    gettl ();
  441. int    getval ();
  442. int    set ();
  443. int    expesc ();
  444. int    specialchar ();
  445. int    fontchange ();
  446. int    getlin ();
  447. int    ngetc ();
  448. int    pbstr ();
  449. int    putbak ();
  450. int    prchar ();
  451. int    put ();
  452. int    putlin ();
  453. int    atod ();
  454. int    robrk ();
  455. int    ctod ();
  456. int    space ();
  457. int    getwrd ();
  458. int    countesc ();
  459. int    itoda ();
  460. int    itoROMAN ();
  461. int    itoroman ();
  462. int    itoLETTER ();
  463. int    itoletter ();
  464. int    min ();
  465. int    max ();
  466. int    defmac ();
  467. int    colmac ();
  468. int    putmac ();
  469. int    maceval ();
  470. int    main ();
  471. int    usage ();
  472. int    init ();
  473. int    pswitch ();
  474. int    profile ();
  475. int    text ();
  476. int    bold ();
  477. int    center ();
  478. int    expand ();
  479. int    justcntr ();
  480. int    justleft ();
  481. int    justrite ();
  482. int    leadbl ();
  483. int    pfoot ();
  484. int    phead ();
  485. int    puttl ();
  486. int    putwrd ();
  487. int    skip ();
  488. int    spread ();
  489. int    strkovr ();
  490. int    underl ();
  491. int    width ();
  492. int    inptobu ();        /* convert input units to b.u. */
  493. int    butochar ();        /* convert b.u. to char spaces */
  494.  
  495. int    findreg ();
  496. int    set_ireg ();
  497.  
  498.  
  499.  
  500. /*
  501.  *    globals. define NRO_MAIN in main.c to define globals there. else
  502.  *    you get extern.
  503.  */
  504. #ifdef NRO_MAIN
  505.  
  506. struct docctl        dc;
  507. struct page        pg;
  508. struct cout        co;
  509. struct macros        mac;
  510. struct regs        rg[MAXREGS];
  511. FILE               *out_stream;
  512. FILE               *err_stream;
  513. FILE               *dbg_stream;
  514. FILE               *sofile[Nfiles+1];
  515. int            ignoring;        /* .ig vs .de */
  516. int            hold_screen;
  517. int            debugging;
  518. int            stepping;        /* paging */
  519. int            mc_ing = 0;        /* turned off */
  520. int            mc_space = 2;
  521. char            mc_char = '|';
  522. char            tmpdir[256];
  523. char            termcap[1030];
  524. char            s_standout[20];
  525. char            e_standout[20];
  526. char            s_bold[20];
  527. char            e_bold[20];
  528. char            s_italic[20];
  529. char            e_italic[20];
  530. char               *dbgfile = "nroff.dbg";
  531. #ifdef GEMDOS
  532. char               *printer = "prn:";    /* this WON'T work!!! */
  533. #else
  534. char               *printer = "/dev/lp";    /* this probably won't */
  535. #endif
  536.  
  537.  
  538. #include "version.h"                /* for myname and version */
  539.  
  540.  
  541. #ifdef ALCYON
  542. /*
  543.  *    this SHOULD be big enough for most needs. only used by startup
  544.  *    code (gemstart.o or crt0.o)
  545.  */
  546. long            _STKSIZ = 16384L;
  547. #endif
  548. #ifdef __SASC
  549. /*
  550.  *    this SHOULD be big enough for most needs. only used by startup
  551.  *    code (scnb.lib)
  552.  */
  553. long        __near    __stack = 16384;
  554. #endif
  555.  
  556.  
  557. #else /*NRO_MAIN*/
  558.  
  559. extern struct docctl    dc;
  560. extern struct page    pg;
  561. extern struct cout    co;
  562. extern struct macros    mac;
  563. extern struct regs    rg[MAXREGS];
  564. extern FILE           *out_stream;
  565. extern FILE           *err_stream;
  566. extern FILE           *dbg_stream;
  567. extern FILE           *sofile[Nfiles+1];
  568. extern int        ignoring;
  569. extern int        hold_screen;
  570. extern int        debugging;
  571. extern int        stepping;
  572. extern int        mc_ing;
  573. extern int        mc_space;
  574. extern char        mc_char;
  575. extern char        tmpdir[];
  576. extern char        termcap[];
  577. extern char        s_standout[];
  578. extern char        e_standout[];
  579. extern char        s_italic[];
  580. extern char        e_italic[];
  581. extern char           *dbgfile;
  582. extern char           *printer;
  583. extern char           *myname;
  584. extern char           *version;
  585. extern int        patchlevel;
  586.  
  587. #endif /*NRO_MAIN*/
  588.  
  589. #endif /*NRO_H*/
  590.  
  591.